import type {
  MenuAddDTOType,
  MenuUpdateDTOType,
  MenuSearchDTOType,
} from '@/resources/interface/menu/MenuTypes.ts'
import type { ResultTypes } from '@/resources/interface/ResultTypes.ts'
import { HttpResultUtil } from '@/apis/utils/HttpResultUtil.ts'

export class MenuApi {
  private static addUrl: string = '/menu/add'
  private static updateUrl: string = '/menu/update'
  private static searchUrl: string = '/menu/search'
  private static deleteUrl: string = '/menu/delete'
  private static menuTreeUrl: string = '/menu/tree'
  private static menuTreeAllUrl: string = '/menu/tree/all'
  private static menuParentUrl: string = '/menu/parent'
  private static menuFindRoleUrl: string ='/menu/find/role'

  static findRoleMenuApi(data:number):Promise<ResultTypes>{
    return HttpResultUtil.awaitGet(this.menuFindRoleUrl,{roleId:data},false)
  }
  static add(data: MenuAddDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.addUrl, data, true)
  }

  static update(data: MenuUpdateDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.updateUrl, data, true)
  }

  static search(data: MenuSearchDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.searchUrl, data, false)
  }

  static delete(idList: Array<number>): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.deleteUrl, idList, true)
  }

  /**
   * 当前用户菜单路由树
   */
  static getMenuTreeApi() {
    return HttpResultUtil.awaitGet(this.menuTreeUrl, null, false)
  }

  static getMenuTreeAllApi() {
    return HttpResultUtil.awaitGet(this.menuTreeAllUrl, null, false)
  }

  static getMenuParentApi() {
    return HttpResultUtil.awaitGet(this.menuParentUrl, null, false)
  }
}
